#ifndef QPROPERTY_H
#define QPROPERTY_H

#include "../../include/abstractproperty.h"

#include <QString>
#include <QList>
#include <QVariant>
#include <QObject>
#include <QIcon>

class XMLProperty;
class AbstractCore;

class QProperty: public QAbstractProperty
{
    Q_OBJECT
public:
    QProperty(const QString &name,QProperty* parent=0);
    ~QProperty();

    QString name();
    QList<QProperty*> children();
    virtual QString valueText();
    virtual QIcon   valueIcon();
    QProperty* parent();

    void    setGroup(const QString &group);
    QString group();

    void    setValue(const QVariant &value);
    QVariant value();

    void        setDefaultValue(QVariant value);
    QVariant    defaultValue();

    bool    modified();
    void    setModified(bool modified);

    bool    enabled();
    void    setEnabled(bool enabled);

    bool    reset();
    void    setReset(bool reset);

    QObject *object();
    void    setObject(QObject *obj);

    bool    needSave();
    void    setNeedSave(bool save);

    void    setCore(AbstractCore *core);
    AbstractCore    *core();

    XMLProperty *xmlProperty();


    void    setAttribute(const QString& key,const QVariant &value);
    QVariant attribute(const QString &key,const QVariant def=QVariant());
protected:
    virtual void    valueChanged();
    void    emitAttributeChanged();
signals:
    void    attributeChanged();
    void    changed();
    void    changed(const QString & name);
protected:
    QString     m_name;
    QString     m_group;
    QVariant    m_value;
    QVariant    m_defaultValue;
    bool        m_enabled;
    bool        m_modified;
    bool        m_reset;

    QList<QProperty*>   m_children;
    QProperty*          m_parent;
    bool                m_needSave;

    QObject     *m_object;
    XMLProperty *m_xmlProperty;

    QMap<QString,QVariant>  m_attributes;
    AbstractCore            *m_core;
};

class QIntProperty: public QProperty
{
    Q_OBJECT
public:
    QIntProperty(const QString &name,QProperty* parent=0);

    QString valueText(){return QString::number(m_value.toInt());}
};

class QFloatProperty: public QProperty
{
    Q_OBJECT
public:
    QFloatProperty(const QString &name,QProperty* parent=0);

    QString valueText(){return QString::number(m_value.toDouble(),'f',attribute("decimals",2).toInt());}
};

class QBoolProperty: public QProperty
{
    Q_OBJECT
public:
    QBoolProperty(const QString &name,QProperty* parent=0);

    QString valueText(){return "";}

    QIcon   valueIcon();
};

class QByteProperty: public QProperty
{
    Q_OBJECT
public:
    QByteProperty(const QString &name,QProperty* parent=0);

    QString valueText(){return m_value.toString();}
};

class QSizeProperty: public QProperty
{
    Q_OBJECT
public:
    QSizeProperty(const QString &name,QProperty* parent=0);

    QString valueText();

    void    setValue(const QVariant &value);
protected:
    void valueChanged();

    QProperty   *m_widthProperty;
    QProperty   *m_heightProperty;
};

class QRectProperty: public QProperty
{
    Q_OBJECT
public:
    QRectProperty(const QString &name,QProperty* parent=0);

    QString valueText();

    void    setValue(const QVariant &value);
protected:
    void valueChanged();

    QProperty   *m_xProperty;
    QProperty   *m_yProperty;
    QProperty   *m_widthProperty;
    QProperty   *m_heightProperty;
};

class QFontFamilyProperty: public QProperty
{
    Q_OBJECT
public:
    QFontFamilyProperty(const QString &name,QProperty* parent=0):QProperty(name,parent){m_value="";}

    QString valueText(){return m_value.toString();}
};

class QFontProperty: public QProperty
{
    Q_OBJECT
public:
    QFontProperty(const QString &name,QProperty* parent=0);

    QString valueText();
    QIcon    valueIcon();

    void    setValue(const QVariant &value);
protected:
    void valueChanged();
protected:
    QProperty   *m_pointSize;
    QProperty   *m_bold;
    QProperty   *m_italic;
    QProperty   *m_underline;
    QProperty   *m_strikeout;
    QProperty   *m_family;
};

class QEnumProperty: public QProperty
{
    Q_OBJECT
public:
    QEnumProperty(const QString &name,QProperty* parent=0);

    QString     valueText();
};

class QCursorProperty: public QProperty
{
    Q_OBJECT
public:
    QCursorProperty(const QString &name,QProperty* parent=0);

    QString valueText();
    QIcon   valueIcon();

    QStringList textList();
    QStringList iconList();

    void    setValue(const QVariant &value);
protected:
    QStringList m_text;
    QStringList m_icon;
};

class QComboItemsProperty: public QProperty
{
    Q_OBJECT
public:
    QComboItemsProperty(const QString &name,QProperty* parent=0);

    QString valueText();
};

class QTimeProperty: public QProperty
{
    Q_OBJECT
public:
    QTimeProperty(const QString &name,QProperty* parent=0);
    QString valueText();
};

class QDateProperty: public QProperty
{
    Q_OBJECT
public:
    QDateProperty(const QString &name,QProperty* parent=0);
    QString valueText();
};

class QDateTimeProperty: public QProperty
{
    Q_OBJECT
public:
    QDateTimeProperty(const QString &name,QProperty* parent=0);
    QString valueText();
};

class QColorProperty: public QProperty
{
    Q_OBJECT
public:
    QColorProperty(const QString &name,QProperty* parent=0);
    QString valueText();

    QIcon valueIcon();
};

class QBorderProperty: public QProperty
{
    Q_OBJECT
public:
    QBorderProperty(const QString &name,QProperty* parent=0);
    QString valueText();

    QIcon valueIcon();
};

class QImageProperty: public QProperty
{
    Q_OBJECT
public:
    QImageProperty(const QString &name,QProperty* parent=0);
    QString valueText();

    void    setValue(const QVariant &value);
    QIcon    valueIcon();
};

class QMemeryValueProperty: public QProperty
{
    Q_OBJECT
public:
    QMemeryValueProperty(const QString &name,QProperty* parent=0);
    QString valueText();
};

class QScriptProperty: public QByteProperty
{
    Q_OBJECT
public:
    QScriptProperty(const QString &name,QProperty* parent=0);
    QString valueText();
};

class QPaddingProperty: public QProperty
{
    Q_OBJECT
public:
    QPaddingProperty(const QString &name,QProperty* parent=0);
    QString valueText();
};

#endif // QPROPERTY_H
